package com.lzw.bluetoothpractice.Adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lzw.bluetoothpractice.Activitys.DetailForumActivity;
import com.lzw.bluetoothpractice.AppConfig;
import com.lzw.bluetoothpractice.R;
import com.lzw.bluetoothpractice.bean.RecommendDoctorBean;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class RecommendDoctorListAdapter extends RecyclerView.Adapter<RecommendDoctorListAdapter.ViewHolder>{
    private List<RecommendDoctorBean.DataBean> datas = new ArrayList<>();
    View itemView;
    Context mcontext;
    public void updateData(List<RecommendDoctorBean.DataBean> data) {
        if (this.datas == null) {
            this.datas = new ArrayList<>();
        }
        this.datas.clear();
        this.datas.addAll(data);
        notifyDataSetChanged();
    }
    public RecommendDoctorListAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        RecommendDoctorBean.DataBean doctorBean = datas.get(position);
        Glide.with(mcontext).load(AppConfig.BASE_URL+doctorBean.getAvatar()).into(holder.detail_doctor_head);
        if (holder instanceof ViewHolder) {
            ((ViewHolder) holder).detail_doctor_introduce.setText(doctorBean.getRemark());

            ((ViewHolder) holder).detail_doctor_phone.setText(doctorBean.getPhonenumber());
            ((ViewHolder) holder).detail_doctor_name.setText(doctorBean.getNickName());
            ((ViewHolder) holder).detail_doctor_introduce.setText(doctorBean.getSpecial());
        }

    }

    @Override
    public int getItemCount() {
        return datas.size();
    }


    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        itemView= LayoutInflater.from(mcontext).inflate(R.layout.recommend_doctor,parent,false);

        return new ViewHolder(itemView);
    }

    class ViewHolder extends RecyclerView.ViewHolder {

    View view;

    ImageView detail_doctor_head;
    TextView detail_doctor_name;
    TextView detail_doctor_phone;
    TextView detail_doctor_introduce;
    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        view=itemView;
        detail_doctor_head=view.findViewById(R.id.detail_doctor_head);
        detail_doctor_name=view.findViewById(R.id.detail_doctor_name);
        detail_doctor_introduce=view.findViewById(R.id.detail_doctor_introduce);
        detail_doctor_phone=view.findViewById(R.id.detail_doctor_phone);




    }
}
}
